package com.wrs.wrsfcmpush.service

import android.app.Notification
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.telecom.CallAudioState
import android.telecom.Connection
import android.util.Log
import androidx.annotation.RequiresApi
import com.blankj.utilcode.util.ToastUtils
import com.wrs.wrsfcmpush.MainActivity
import com.wrs.wrsfcmpush.R

@RequiresApi(Build.VERSION_CODES.M)
class CallConnection(ctx: Context) : Connection() {

    var ctx:Context = ctx
    var tag = "voip CallConnection"
//    override fun onShowIncomingCallUi() {
//        super.onShowIncomingCallUi()
//    }
//    override fun onShowIncomingCallUi() {
//        super.onShowIncomingCallUi()
//        Log.i(tag, "onShowIncomingCallUi")
//        val intent = Intent(Intent.ACTION_MAIN, null)
//        intent.flags = Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_ACTIVITY_NEW_TASK
//        intent.setClass(ctx, MainActivity::class.java!!)
//        val pendingIntent = PendingIntent.getActivity(ctx, 1, intent, PendingIntent.FLAG_IMMUTABLE)
//        val builder = Notification.Builder(ctx)
//        builder.setOngoing(true)
//        builder.setPriority(Notification.PRIORITY_HIGH)
//
//        // Set notification content intent to take user to fullscreen UI if user taps on the
//        // notification body.
//        builder.setContentIntent(pendingIntent)
//        // Set full screen intent to trigger display of the fullscreen UI when the notification
//        // manager deems it appropriate.
//        builder.setFullScreenIntent(pendingIntent, true)
//
//        // Setup notification content.
//        builder.setSmallIcon(R.mipmap.ic_launcher)
//        builder.setContentTitle("Your notification title")
//        builder.setContentText("Your notification content.")
//
//        // Use builder.addAction(..) to add buttons to answer or reject the call.
//
//        val notificationManager = ctx.getSystemService(
//            Context.NOTIFICATION_SERVICE) as NotificationManager
//
//        notificationManager.notify("Call Notification", 37, builder.build())
//    }

    override fun onCallAudioStateChanged(state: CallAudioState?) {
        Log.i(tag, "onCallAudioStateChanged")
    }

    override fun onAnswer() {
        super.onAnswer()
        Log.i(tag, "onAnswer")
        // 处理接听通话的逻辑
        ToastUtils.showLong("onAnswer")
    }

    override fun onDisconnect() {
        super.onDisconnect()
        Log.i(tag, "onDisconnect")
        ToastUtils.showLong("onDisconnect")
        // 处理挂断通话的逻辑
    }

    override fun onHold() {
        Log.i(tag, "onHold")
        ToastUtils.showLong("onHold")
    }

    override fun onUnhold() {
        Log.i(tag, "onUnhold")
    }

    override fun onReject() {
        Log.i(tag, "onReject")
    }
}